<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>购物超市</title>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,user-scalable=no" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="stylesheet" type="text/css"
          href="../static/bootstrap3/css/bootstrap.css">
    <link rel="stylesheet" type="text/css"
          href="../static/bootstrap3/font-awesome-4.7.0/css/font-awesome.css" />
    <style>

        .header{
            width: 990px;
            height: 88px;
            margin: 0 auto;

        }
        .logo img{
            width: 190px;
            height: 88px;
            float: left;
            margin-right: 24px;

        }
        .logo-text{
            float: left;
            font-size: 18px;
            color: #666;
            line-height: 88px;
        }
        .login{
            float: right;
            margin-top: 63px;
            text-decoration: none;
            margin-left: 10px;
        }
        .main{
            width: 990px;
            margin: 0 auto;
            border: 1px solid #ddd;
            border-top: 3px solid #f90;
            background: #fff;
            padding: 64px 0;
            line-height: 1.5;
        }
        .reg-form{
            width: 510px;
            position: relative;
            margin: 0 auto;

        }
        .input-box{
            width: 360px;
            height: 38px;
            border: 1px solid #ccc;
            line-height: 38px;
            margin-bottom: 25px;
        }
        .title{
            float: left;
            width: 78px;
            padding-left: 11px;
        }
        .input-box input{
            display: inline-block;
            width: 77%;
            height: 100%;
            font-size: 14px;
            color: #333;
            border: 0;
            background: 0;
            position: relative;
            padding: 0px 10px;
            margin: 0 auto;
            top: -1px;
        }
        .input-submit{
            width: 360px;
            height: 38px;
            border: 1px solid #ccc;
            line-height: 38px;
            margin-bottom: 25px;
        }
        .input-submit input{
            display: inline-block;
            width: 100%;
            height: 100%;
            font-size: 22px;
            color: white;
            border: 0;
            background: #ff7e00;
        }
        .input-submit input:hover{
            cursor: pointer;
            background: #ff5e03;
        }

        .email{
            position: absolute;
            top: 5px;
            height: 36px;
            left: 363px;
        }
        .main_1{
            position: relative;
            left: 50px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
<div class="header">
    <a href="" class="logo"><img src="photo/小猪折扣.png"></a>
    <div class="logo-text" >用户改密</div>
    <a href="http://localhost:8080/loginNow" class="login">登录</a>
    <a href="http://localhost:8080/regNow" class="login">注册</a>
</div>

<div class="main">
    <div class="main_1">
        <form action="/change_check" method="post">
            <div class="reg-form">
                <div class="input-box" id="user">
                    <label class="title">用户名</label>
                    <input type="text" name="username" id="name" placeholder="请输入用户名">
                    <p style="color:#ff0000;position: relative;margin: -5px auto">{{msg}}</p>
                </div>
            </div>
            <div class="reg-form">
                <div class="input-box">
                    <label class="title">邮箱</label>
                    <input type="text" name="mailIndex" id="captcha" placeholder="请输入邮箱">
                </div>
                <div class="email">
                    <button id="email">免费获取验证码</button>
                </div>
            </div>
            <div id="pwd">
                <div class="reg-form">
                    <div class="input-box">
                        <label class="title">密码</label>
                        <input type="password" name="password1" id="password1" placeholder="请输入密码">
                    </div>
                </div>
                <div class="reg-form">
                    <div class="input-box">
                        <label class="title">确认密码</label>
                        <input type="password" name="password2" id="password2" placeholder="请输入确认密码">
                        <p style="color:#ff0000;position: relative;margin: -5px auto">{{msg}}</p>
                    </div>
                </div>

            </div>
            <div class="reg-form">
                <div class="input-box">
                    <label class="title">验证码</label>
                    <input type="text" name="captcha" placeholder="请输入验证码">
                    <p style="color:#ff0000;position: relative;margin: -5px auto" th:text="${changepwd}"></p>
                </div>
            </div>
            <div class="reg-form">
                <div class="input-submit">
                    <input type="submit" id="sub" value="确认修改">
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script type="text/javascript" src="../static/bootstrap3/jquery.min.js"></script>
<script type="text/javascript" src="../static/bootstrap3/js/bootstrap.js"></script>
<script type="text/javascript" src="../static/bootstrap3/js/holder.js"></script>
<script type="text/javascript" src="../static/bootstrap3/js/html5shiv.min.js"></script>
<script type="text/javascript" src="../static/bootstrap3/js/css3-mediaqueries.js"></script>
<script type="text/javascript" src="../static/bootstrap3/js/respond.min.js"></script>
<script type="text/javascript" src="../static/bootstrap3/jquery-3.4.1.js"></script>
<script src="../static/js/vue.js"></script>
<script>
    let waitTime = 60;
    function time(ele) {

        if (waitTime == 0) {
            ele.disabled=false;
            ele.innerHTML = "免费获取验证码";
            waitTime = 60;// 恢复计时
        } else {
            ele.disabled=true;
            ele.innerHTML = waitTime + "秒后可以重新发送";
            waitTime--;
            setTimeout(function() {
                time(ele)// 关键处-定时循环调用
            }, 1000)
        }
    }

    let app1 = new Vue({
        el: "#user",
        data: {
            msg: ""
        }
    });
    //给用户名文本框添加失去焦点事件
    $("#name").blur(function () {
        //失去焦点时 通过ajax发出请求 检查用户名是否可用
        $.ajax({
            type:"get",
            url:"LoginName",
            data:"username="+$("#name").val(),
            success : function (msg) {
                app1.msg = msg;
                checkreg(msg);
            }
        });
    });
    let app2 = new Vue({
        el: "#pwd",
        data: {
            msg: ""
        }
    });
    //给用户名文本框添加失去焦点事件
    $("#password2,#password1").blur(function () {

        //失去焦点时 通过ajax发出请求 检查用户名是否可用
        $.ajax({
            type:"get",
            url:"password",
            data:{"password1":$("#password1").val(),"password2":$("#password2").val()},
            success : function (msg) {
                app2.msg = msg;
                checkreg(msg);
            }
        });
    });

    $("#email").click(function () {
        $.ajax({
            type: "get",
            url: "change_email",
            data: "mailIndex="+$("#captcha").val(),
        });
        time(this);
    });

    function checkreg(str) {
        if ("请输入密码"==str||"密码不一致"==str||"用户名不存在"==str){
            $("#sub").prop("disabled",true);
        }else {
            $("#sub").prop("disabled",false);
        }
    }

</script>
</html>